package com.victualler.core.config.permission.controller.impl;

import com.victualler.core.base.controller.impl.BaseRestControllerImpl;
import com.victualler.core.common.dto.PageDto;
import com.victualler.core.config.permission.controller.PermissionInfoController;
import com.victualler.core.config.permission.dto.PermissionGroupDto;
import com.victualler.core.config.permission.dto.request.PermissionRequestDto;
import com.victualler.core.config.permission.entity.PermissionInfoDao;
import com.victualler.core.config.permission.repository.PermissionInfoQueryRepository;
import com.victualler.core.config.permission.repository.PermissionInfoRepository;
import com.victualler.core.config.permission.service.PermissionInfoService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * @author: Guoshichang
 * @discription:  权限管理相关页面
 */
@RestController
@RequestMapping("/core/config/permission/permission")
public class PermissionInfoControllerImpl extends BaseRestControllerImpl<PermissionInfoDao,PermissionInfoRepository,PermissionInfoQueryRepository,PermissionInfoService> implements PermissionInfoController {
    /**
     * @author Guoshichang
     * @since 13:39 on 2018/7/7.
     * @param permissionRequestDto
     * @Function  根据条件入参PermissionRequestDto动态分页查询权限
     */
    @RequestMapping("/getByRequestDto")
    @Override
    public PageDto<PermissionInfoDao> getByRequestDto(@RequestBody PermissionRequestDto permissionRequestDto, @RequestParam("pageNo") int pageNo,@RequestParam("limit") int limit) {
        return this.baseService.getByRequestDto(permissionRequestDto,pageNo,limit);
    }

    /**
     * @author Guoshichang
     * @since 16:30 on 2018/8/28.
     * @param name 权限名称
     * @return List
     * @Function 根据权限名称模糊查询
     */
    @RequestMapping("/getByName")
    public List<PermissionInfoDao> getByName(@RequestParam("name") String name) {
        return this.baseService.getByName(name);
    }


    @RequestMapping("/getByRoleId")
    public PermissionGroupDto getByRoleId(@RequestParam("roleId") Long roleId) {
        List<PermissionInfoDao> myPermissionList = this.baseService.getByRoleId(roleId);
        List<PermissionInfoDao> allPermissionList = this.baseService.notInByRoleId(roleId);
        return new PermissionGroupDto(allPermissionList,myPermissionList);
    }
}
